package cn.oms.oms.utils;

import java.util.Calendar;
import java.util.Date;

public class AgeTools {

    public static Integer ageCalculator(Date birthDay){

        Calendar calendar = Calendar.getInstance();
        if (calendar.before(birthDay)){
            throw new IllegalArgumentException("当前时间早于出生时间");
        }
        Long birthMills = birthDay.getTime();
//        Calendar testDate = Calendar.getInstance();
        /*测试数据，忽略即可
        testDate.set(1998,9,8);
        long testTime = testDate.getTimeInMillis();*/
        Long nowMills = calendar.getTimeInMillis();
        Long liveMills = nowMills - birthMills;
        Long yearMills = (long)365*24*60*60*1000;
        int age = (int) (liveMills / yearMills);
        return age;

    }
}
